import { showConfirmDialog } from 'vant'
import { useRouter, useRoute } from 'vue-router'
import { useUserStore } from '@/store'

export function useLoginConfirm () {
  const router = useRouter()
  const route = useRoute()
  const user = useUserStore()

  const loginConfirm = () => {
    if (!user.userInfo.token) {
      showConfirmDialog({
        title: '温馨提示',
        message: '您需要先登录才能继续操作哦',
        confirmButtonText: '去登录',
        confirmButtonColor: '#ff5b5b',
        cancelButtonText: '再逛逛'
      }).then(() => {
        router.replace({
          path: '/login',
          query: {
            backUrl: route.fullPath
          }
        })
      }).catch(() => {})
      return true
    }
    return false
  }

  return { loginConfirm }
}
